<template>
  <div>
    <h2>物流相关信息</h2>
    <div class="logistics-info-header">
      <div class="logistics-info-header-left">
        <div class="logistics-status blue" ref="boxli">
          {{ stateList }}
        </div>
        <div class="logistics-company">{{ orderInfo.logisticsCompany }}</div>
        <div class="logistics-no">{{ orderInfo.logisticsNo }}</div>
      </div>
    </div>
    <ul class="logistics-info-list">
      <li v-for="item in orderInfo.logisticsInfo" :key="item.time">
        <div class="logistics-info-list-time">{{ item.time }}</div>
        <div class="logistics-info-list-content">{{ item.content }}</div>
      </li>
    </ul>
    <button v-determine="orderInfo.role">查看物流详情</button>
  </div>
</template>

<script>
export default {
  directives: {
    determine: {
      inserted(el, { value }) {
        switch (value) {
          case "admin":
            el.disabled = false;
            break;
          case "zhangsan":
            el.disabled = false;
            break;
          case "lisi":
            el.disabled = false;
            break;
          default:
            el.disabled = true
            break;
        }
      },
      update(el, { value }) {
        // const flag = (value === 'admin' || 'zhangsan' || 'lisi')
        switch (value) {
          case "admin":
            el.disabled = false;
            break;
          case "zhangsan":
            el.disabled = false;
            break;
          case "lisi":
            el.disabled = false;
            break;
          default:
            el.disabled = true
            break;
        }
        //   if(value === 'admin' || 'zhangsan' || 'lisi'){
        //     console.log(1);
        //     console.log(value === 'admin' || 'zhangsan' || 'lisi');
        //   el.disabled=false
        //  }else{
        //   console.log(2);
        //   el.disabled=true
        //  }
      },
    },
  },
  name: "Mylogistics",
  props: {
    orderInfo: Object,
  },
  computed: {
    stateList() {
      switch (this.orderInfo.logisticsStatus + 1) {
        case 1:
          this.$nextTick(() => {
            this.$refs.boxli.classList.add("box");
          });
          return "未发货";
          break;
        case 2:
          this.$nextTick(() => {
            this.$refs.boxli.classList.add("box1");
          });
          return "已发货";
          break;
        case 3:
          this.$nextTick(() => {
            this.$refs.boxli.classList.add("box2");
          });
          return "已签收";
          break;
        case 4:
          this.$nextTick(() => {
            this.$refs.boxli.classList.add("box3");
          });
          return "未签收";
          break;

        default:
          return "";
          break;
      }
    },
    dataLength() {
      return this.orderInfo.logisticsInfo.length - 1;
    },
  },
  methods: {},
};
</script>

<style scoped lang="less">
.logistics-info {
  border: 1px solid #ccc;
  border-radius: 5px;
  box-shadow: 0px 0px 10px #eee;
  padding: 10px;
  font-size: 14px;
}

.logistics-info-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.logistics-info-header-left {
  display: flex;
  align-items: center;
}

.logistics-status {
  font-weight: bold;
  font-size: 16px;
  color: #007bff;
}

.logistics-company,
.logistics-no {
  margin-left: 10px;
  font-size: 14px;
  color: #333;
}

.logistics-info-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 230px;
  overflow-y: auto;
}

.logistics-info-list li {
  display: flex;
  margin-bottom: 10px;
}

.logistics-info-list-time {
  font-size: 12px;
  color: #999;
  width: 80px;
  text-align: right;
  margin-right: 10px;
}

.logistics-info-list-content {
  font-size: 14px;
  color: #333;
}
.box {
  color: red;
}
.box1 {
  color: pink;
}
.box2 {
  color: #087;
}
.box3 {
  color: lawngreen;
}
</style>
